package com.miao.view
{
	import flash.display.NativeMenu;
	import flash.display.NativeMenuItem;
	import flash.display.NativeWindow;
	import flash.events.Event;
	
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	public class WindowMenuMediator extends Mediator
	{
		
		public static const NAME:String = "WindowMenuMediator";
		
		public function WindowMenuMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
			
			initMenu();
		}
		
		private function initMenu():void{
			if(NativeWindow.supportsMenu){
				var menuWin:NativeMenu = new NativeMenu();
				var downloadWin:NativeMenuItem = new NativeMenuItem("下载管理器", false);
				downloadWin.addEventListener(Event.SELECT, handleMenuEvt);
				menuWin.addItem(downloadWin);
				
				var menu:NativeMenu = new NativeMenu();
				menu.addSubmenu(menuWin, "窗口");
				player.nativeWindow.menu = menu;
			}else{
				trace("不支持系统菜单，部分功能将不能使用！");
			}
		}
		
		private function handleMenuEvt(e:Event):void{
			var menu:NativeMenuItem = e.currentTarget as NativeMenuItem;
			
			if(e.type==Event.SELECT){
				switch(menu.label){
					case "下载管理器":{
						var dlm:DownLoadManagerMediator = facade.retrieveMediator(DownLoadManagerMediator.NAME) as DownLoadManagerMediator;
						dlm.openWindow();
						break;
					}
				}
			}
		}
		
		private function get player():StudyPlayer{
			return viewComponent as StudyPlayer;
		}
	}
}